<style>
  .layui-laypage a, .layui-laypage span{
    background-color: #f2f2f2;
  }
  .layui-table-page{
      text-align: center
  }
</style>

<div style="margin:1% 5%;">
  <div class="layui-form-item" style=";padding-left: 30%;">

    <div class="layui-input-inline">
      <input type="text" id="macfjval" placeholder="请输入房间号/mac地址/ip" autocomplete="off" class="layui-input">

    </div>
    <label class="layui-form-label" style="padding: 0!important;"><button type="button" class="layui-btn" id="btnSearch" lay-event="shousuo">搜索</button></label>
  </div>
</div>
<div style="padding-left: 50px;">
  <caption style="margin-left: 40px;"><span >
                <button type="button" class="btn btn-primary layui-btn"  onclick="method5('tableExcel')">
                    <span class="glyphicon glyphicon-folder-open">导出Excel</span>
                </button>
            </span>
  </caption>
</div>

<script type="text/html" id="tol">
  <div>
    <div style="float:left;">终端授权列表</div>
    <div style="float:right;margin-right: 50px">共有数据：<span id="count"></span>条</div>
  </div>

</script>
<table class="layui-table" id="data2" lay-filter="data2">

</table>
<div id="demo7" style="text-align: center"></div>


<script type="text/html" id="caozuo">
      <button type="button" class="layui-btn" lay-event="detail">密钥授权</button>


</script>

<script>

    var local_store = layui.data("local_store");
    var local = local_store.token;
    $.ajax({
        type:"get",
        url:"/admin/station/query/stationLoginQuanxXian?stationId="+json.id,
        dataType: "json",
        contentType:"application/json;charset=utf-8",
        beforeSend: function(request) {
            request.setRequestHeader("token", local);
        },
        success:function (res) {
            if(res.code==500){
                alert("权限不足")
                location="../../admin/main.html";
                return
            }}})

  function GetRequest() {
    var url = decodeURI(location.search); //获取url中"?"符后的字串
    var theRequest = new Object();
    if (url.indexOf("?") != -1) {
      var str = url.substr(1);
      strs = str.split("&");
      for(var i = 0; i < strs.length; i ++) {
        theRequest[strs[i].split("=")[0]]=unescape(strs[i].split("=")[1]);
      }
    }
    return theRequest;
  }

  var json=GetRequest();

  var pages= localStorage.getItem('page');

  localStorage.setItem('groupStationId',json.id);
  layui.use('table', function(){
    var table = layui.table;

    table.render({
      elem: '#data2'
      ,  id: "t"
      ,  toolbar:"#tol"
      , method: 'post'
      ,url:'/admin/terminal/queryIpMacFjAll?terminalStation='+json.id
      ,cols: [[
        {field:'terminal_id', title: '终端编号', width: "7%",
          align: "center"}
        ,{field:'terminal_ip', title: 'IP地址',width: "10%",
          align: "center"}
        ,{field:'terminal_mac', width: "12%",
          align: "center", title: 'MAC地址'}
        ,{field:'terminal_key',width: "8%",
          align: "center",  title: '密码'}
        ,{field:'station_bh', title: '站点编号',width: "8%",
          align: "center"} //minWidth：局部定义当前单元格的最小宽度，layui 2.2.1 新增
        ,{field:'terminal_room', width: "8%",
          align: "center", title: '房间号'}
        ,{field:'terminal_line',width: "8%",
          align: "center",  title: '是否在线'}
        ,{field:'group_name', width: "8%",
          align: "center", title: '所属分组'}
        ,{field:'terminal_version_code',width: "6%",
          align: "center", title:'版本'}
        ,{field:'terminal_system_model', width: "6%",
          align: "center", title: '型号'}
        ,{
          title:'操作',
          align:'center',
          toolbar:'#caozuo',
          fixed: 'right'
        }
      ]],page:true,
        limit:40,
      done: function(res, curr, count){
          localStorage.setItem('page',curr);
        $("#count").html(count);
      }
    });
    table.on('tool(data2)',function(obj){
      var getdata=obj.data; //获取当前行数据
      var layEvent=obj.event; //获取lay-event对应的值,(也可以是表头的event参数对应的值)
      var tr=obj.tr; //获取当前行tr的DOM对象(如果有的话)
        var stationBh=getdata.station_bh;
        switch(layEvent){

            case "detail":
                $.ajax({
                   url: '/admin/terminal-key/selectPassword?station_id='+stationBh+"&terminal_id="+getdata.terminal_id
                ,method:"get",
                    success:function (res) {
                       if (res.msg=="已授权"){
                           console.log(res.msg)

                           layer.msg('该终端已授权密钥！', {icon: 2,time: 1000});
                           return;
                       } else{
                           layui.data("s",{key:"terminal",value:getdata});
                           layer.open({
                               title:"密钥授权",
                               type:2,
                               content:'/admin/station_config/views/layui/terminal_empower.html?stationBh='+stationBh,
                               area:['800px','500px']
                           });
                           templet:{
                               localStorage.setItem("stationid",json.id);
                           }
                       }
                    }
                })

                break;
        }
    });
    $("#btnSearch").click(function(){
      table.reload("t",{
        where:{
          macfj:$("#macfjval").val()
        },
        page:{
          curr:1
        }
      });
    });
  });

</script>

